﻿
Public Module _include
    Public Const name As String = "include"
    Public Const separator As Char = character.blank

    Private Sub predictcb(ByVal line As String, ByRef output As String)
        Dim file As String = Nothing
        If strseg(line, Nothing, file, separator) Then
            Dim content As String = Nothing
            If Not readfile(file, content) Then
                raiseError("cannot read file " + file + ", ignore.", errorHandle.errorType.user)
            ElseIf Not isemptystring(content) Then
                output += content
            End If
        Else
        raiseError("do not have an include file defined in include predict, ignore.", _
                   errorHandle.errorType.user)
        End If
    End Sub

    Private Sub include(ByVal script As String, ByRef output As String)
        predict(script, output, name, AddressOf predictcb)
    End Sub

    Public Sub include(ByRef script As String)
        Dim output As String = Nothing
        include(script, output)
        script = output
    End Sub
End Module
